class UsersController < ApplicationController
  # Be sure to include AuthenticationSystem in Application Controller instead
  #include AuthenticatedSystem
  layout "general"
  # render new.rhtml
  def new
  end

  def create
    @user = User.new(params[:user])
    @user.save!
    
    bc = Broadcast.create(:site => 2, :from=>0, :to=>0, :content=>"欢迎 <a href=\"#{user_path(@user)}\">#{@user.login}</a> 注册为多背一公斤志愿者，参加多背一公斤爱心公益助学计划活动")
    
    self.current_user = @user
    redirect_back_or_default('/')
    #flash[:notice] = "谢谢您注册为GatherLove会员 :)"
  rescue ActiveRecord::RecordInvalid
    render :action => 'new'
  end

  def show
    @user = User.find(params[:id])
    @broadcasts = Broadcast.find(:all,
                                 :conditions => "broadcasts.site=2 and broadcasts.from=#{@user.id}",
                                 :order => "broadcasts.created_at desc",
                                 :joins => "left join users on broadcasts.from = users.id",
                                 :select => "broadcasts.content, broadcasts.from, broadcasts.created_at, users.login, users.id") if @user
    
    respond_to do |format|
      format.html
    end
  end
end
